package leetcode.recursive;

import java.util.ArrayList;
import java.util.List;

//784. 字母大小写全排列
public class LetterCasePermutation {
    public static void main(String[] args) {
        String s = "a1b2";
        System.out.println(letterCasePermutation(s).toString());
    }

    public static List<String> letterCasePermutation(String s) {
        List<String> res = new ArrayList<>();
        char[] chars = s.toCharArray();
        dfs(chars, 0, s.length(), res);
        return res;
    }

    private static void dfs(char[] chars, int start, int length,
                            List<String> res) {
//        if (start==length){
//            return;
//        }
        res.add(new String(chars));  //将自己先加入集合
        for (int i = start; i < length; i++) {
            if (!Character.isDigit(chars[i])) {
                char tmp = chars[i];
                chars[i] = (char) (chars[i] - 'a' >= 0 ? chars[i] - 32 : chars[i] + 32);
                dfs(chars, i + 1, length, res);
                //撤销
                chars[i] = tmp;
            }
        }
    }

}
